package RabbitMQ.Simple;
import com.rabbitmq.client.*;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
public class ConsumerDemo {
    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory connectionFactory=new ConnectionFactory();
        connectionFactory.setHost("203.33.207.200");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("zhangxuan");
        connectionFactory.setPassword("zhangxuan");
        connectionFactory.setVirtualHost("maqiu");
        Connection connection=connectionFactory.newConnection();
        Channel channel=connection.createChannel();
        channel.queueDeclare("hello",true,false,false,null);
        DefaultConsumer consumer=new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("从RabbitMQ中接受的消息: "+new String(body));
            }

        };
        channel.basicConsume("hello",true,consumer);
        channel.close();
        connection.close();
    }
}

